<template>
	<view class="bg-fff">
		<view class="fs18 c-000 center fwb ellipsis-2 py10 px10">{{detailItem.title}}</view>
		<view class="dis-flex flex-align-center py10 px10" style="flex-direction: row-reverse;" @tap="share">
			<u-icon class="ml20" name="share-square" color="#5B769F" labelColor="#5B769F" label="分享" size="45" label-size="24"></u-icon>	
			<view class="fs14 c-999 right">发布时间：{{$u.timeFormat(detailItem.createtime, 'yyyy-mm-dd')}}</view>
		</view>
		<view class="breakall">
			<u-parse :content="detailItem.content"></u-parse>
		</view>
	</view>
</template>

<script>
	import uniCopy from '@/common/uni-copy.js'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		data() {
			return {
				detailItem:{},
				uid:'',
				id:''
			}
		},
		
		onLoad(option) {
			this.id = option.id || '';
			this.uid = option.uid || '';
			this.getDetail();
		},
		
		methods: {
			getDetail(){
				this.$http.post(this.$config.UrlNewDetail, {
					id: this.id,
					uid:this.uid
				}, {
					log: true,
					header: {
						'content-type': 'application/json'
					}
				}).then((res) => {
					if(res.code == 1){
						this.detailItem = res.data || {}
					}else this.$api.toast(res.msg);
				})
			},
			
			share(){
				if(!this.hasLogin){
					this.$api.openWindow('/pages/login/login');
					return;
				}
				uniCopy({
					content: `${this.$store.state.host}#/pages/center/newsDetail?id=${this.id}&uid=${this.userInfo.id}`,
					success: (res) => {
						this.$api.toast("链接已复制，可微信等分享给好友");
					},
					error: (e) => {
						this.$api.toast(e);
					}
				})
			},
		}
	}
</script>

<style>
	.sign-circle {
		width: 18rpx;
		height: 18rpx;
		border-radius: 10rpx;
		display: inline-block;
		margin-right: 10rpx;
	}

	.news-des {
		background: #fff;
		position: relative;
		overflow: hidden;
	}

	.news-des img {
		max-width: 100% !important;
		width: 100% !important;
	}
</style>
